package com.yfp.machine.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.machine.domain.MachineTemp;
import com.yfp.machine.domain.dto.FrequencyReportDTO;
import com.yfp.machine.service.MachineTempService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Description: 设备温度记录
 * 
 * @CreateDate: 2024/9/26 10:34
 * @UpdateUser: 
 * @UpdateDate: 2024/9/26 10:34
 * @UpdateRemark: 暂无修改
 * @Version: 1.0
 */
@Tag(name = "设备温度记录")
@RestController
@RequestMapping("machineTemp")
public class MachineTempController extends BaseController {
    @Autowired
    private MachineTempService machineTempService;

    @GetMapping("/findPage")
    @Operation(summary = "分页查询")
    public R<TableDataInfo<List<MachineTemp>>> findPage(@Parameter(name = "machineId") @Valid String machineId,
                                                        @Parameter(name = "startDate") Date startDate,
                                                        @Parameter(name = "endDate") Date endDate) {
        startPage();
        List<MachineTemp> machineTemps = machineTempService.findByMachineId(machineId, startDate, endDate);
        return R.ok(getDataTable(machineTemps));
    }

    @GetMapping("/findAll")
    @Operation(summary = "条件查询全部")
    public R<List<MachineTemp>> findAll(@Parameter(name = "machineId") @Valid String machineId,
                                        @Parameter(name = "startDate") Date startDate,
                                        @Parameter(name = "endDate") Date endDate) {
        List<MachineTemp> machineTemps = machineTempService.findByMachineId(machineId, startDate, endDate);
        return R.ok(machineTemps);
    }

    @PostMapping("/frequencyReport")
    @Operation(summary = "温度上传频率")
    public R<Void> frequencyReport(@RequestBody FrequencyReportDTO frequencyReportDTO) {
        machineTempService.frequencyReport(frequencyReportDTO);
        return R.ok();
    }

    @GetMapping("/frequency")
    @Operation(summary = "获取上传频率")
    public R<Integer> getFrequency(String machineId) {
        Integer frequency = machineTempService.getFrequency(machineId);
        return R.ok(frequency);
    }
}
